//
//  MGTaxAndfeesUtil.m
//  MortgageHelper
//
//  Created by zhangxiang on 16/11/30.
//  Copyright © 2016年 zhangxiang. All rights reserved.
//

#import "MGTaxAndfeesUtil.h"


@implementation MGTaxAndfeesUtil


+(MGTaxAndfeesModel *)TaxAndfeeswithcheckTransferPrice:(NSString *)checkTransferPrice area:(NSString *)area priceOfHouse:(NSString *)priceOfHouse housetype:(NSInteger )housetype timetype:(NSInteger )timetype onlyHouse:(NSInteger )onlyHouse firsthouse:(NSInteger )firsthouse sfjz:(NSInteger )sfjz{
    
    double theVAT =0;   // 增值税
    double Deedtax=0;   // 契税
    double Incometax=0; // 个税
    double Landtax =checkTransferPrice.doubleValue*0.1;  //综合地价税
    double stamptax=5;  // 印花税
    
    // 增值税
    if (timetype==1) {      // 不满两年
        theVAT =((checkTransferPrice.doubleValue)/(1+0.05))*0.05;
    }else{
        if (housetype==1 || housetype==3 ) { // 普通
            theVAT=0;
        }else{              // 非普通
            if (checkTransferPrice.doubleValue>priceOfHouse.doubleValue) {
                theVAT= ((checkTransferPrice.doubleValue-priceOfHouse.doubleValue)/(1+0.05))*0.05;
            }else
                theVAT=0;
        }
    }
    //契税
    if (firsthouse==1) { // 买家一套
        if (housetype == 3) {
            Deedtax=checkTransferPrice.doubleValue*0.015;
        }else
        {
            if (area.doubleValue<=90) {
                Deedtax=(checkTransferPrice.doubleValue - theVAT)*0.01;
            }else{
                Deedtax=(checkTransferPrice.doubleValue - theVAT)*0.015;
            }
        }
        
    }else{
        Deedtax=checkTransferPrice.doubleValue*0.03;
    }
    
    // 个税
    
    if (timetype == 3 && onlyHouse == 1) {
        Incometax=0;
    }else
    {
        if (housetype == 1) {
            if (sfjz == 1) {
                if (checkTransferPrice.doubleValue>theVAT) {
                    Incometax=(checkTransferPrice.doubleValue-theVAT)*0.01 ;
                }else {
                    Incometax=0;
                }
            }else{
                if (checkTransferPrice.doubleValue>priceOfHouse.doubleValue) {
                    Incometax=(checkTransferPrice.doubleValue-priceOfHouse.doubleValue)*0.2 ;
                }else {
                    Incometax=0;
                }
            }
        }else if(housetype == 2)
        {
            if (sfjz == 1) {
                if (checkTransferPrice.doubleValue>theVAT) {
                    Incometax=(checkTransferPrice.doubleValue-theVAT)*0.015 ;
                }else {
                    Incometax=0;
                }
            }else{
                if (checkTransferPrice.doubleValue>priceOfHouse.doubleValue) {
                    Incometax=(checkTransferPrice.doubleValue-priceOfHouse.doubleValue)*0.2 ;
                }else {
                    Incometax=0;
                }
            }
        }else
        {
        if (sfjz == 1) {
            if (checkTransferPrice.doubleValue>theVAT) {
                Incometax=(checkTransferPrice.doubleValue-theVAT)*0.01 ;
            }else {
                Incometax=0;
            }
        }else{
            if (checkTransferPrice.doubleValue>priceOfHouse.doubleValue) {
                Incometax=(checkTransferPrice.doubleValue-priceOfHouse.doubleValue)*0.2 ;
            }else {
                Incometax=0;
            }
        }
        }
    }
    
    
    MGTaxAndfeesModel *model=[[MGTaxAndfeesModel alloc] init];
    model.registerFee = 80.0;
    if (housetype==3) {
        model.vaTax=0;
        model.deedTax=Deedtax;
        model.oneTax=Incometax;
        model.landtax=Landtax;
        model.stampDuty=stamptax;
        model.housePrice=priceOfHouse;
        model.total=(int)Deedtax+(int)Incometax+(int)Landtax+(int)stamptax+80.0;
        
    }else{
        model.vaTax=[[NSString stringWithFormat: @"%.2lf", theVAT] doubleValue]  ;
        model.deedTax=Deedtax;
        model.landtax=0;
        model.oneTax=Incometax;
        model.stampDuty=stamptax;
        model.housePrice=priceOfHouse;
        model.total=[[NSString stringWithFormat: @"%.2lf", ((int)theVAT+(int)Deedtax+(int)Incometax+(int)stamptax+80.0)] doubleValue];
        
    }
    return model;
    
}

@end

@implementation MGTaxAndfeesModel
+(NSDictionary *)replacedKeyFromPropertyName
{
    return @{@"Id":@"id",
             };
}

@end

